﻿Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
  Private Sub Form1_Load(
        ByVal sender As Object,
        ByVal e As System.EventArgs) _
        Handles Me.Load
    Me.SqlConnection1.ConnectionString =
      "Integrated Security=SSPI;" &
      "Persist Security Info=False;" &
      "User ID='';" &
      "Initial Catalog=03_Customers_and_Orders;" &
      "Data Source=(local);" &
      "Initial File Name=''"
  End Sub

  Private Sub btnLeggiRecord_Click(
        ByVal sender As System.Object,
        ByVal e As System.EventArgs) _
        Handles btnLeggiRecord.Click
    Using cn As SqlConnection =
       New SqlConnection(
        Me.SqlConnection1.ConnectionString)
      cn.Open()
      Using cmd As SqlCommand =
          New SqlCommand()
        cmd.CommandType =
          CommandType.StoredProcedure
        cmd.CommandText =
          "spLeggiRecord"
        cmd.Connection = cn
        Dim dr As SqlDataReader =
          cmd.ExecuteReader()
        While dr.Read()
          Me.ListBox1.Items.Add(
            dr("last_name"))
        End While
      End Using
    End Using
  End Sub
End Class
